import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:multi_image_picker_view/multi_image_picker_view.dart';

import '../../widgets/text_button.dart';
import 'rename_controller.dart';

class RenamePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<RenameController>(
        init: RenameController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(
                title: Text('重命名'),
              ),
              body: Container(
                  margin: EdgeInsets.all(15),
                  child: Row(
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                              height: windowHeight * 0.1,
                              child: Row(
                                children: [
                                  SizedBox(
                                      width: windowWidth * 0.1,
                                      child: TextField(
                                          controller:
                                              controller.nameEditingController,
                                          decoration: InputDecoration(
                                              hintText: '请输入名称'))),
                                  SizedBox(
                                    width: 20,
                                  ),
                                  SizedBox(
                                      width: windowWidth * 0.12,
                                      child: TextField(
                                          controller: controller
                                              .indexTextEditingController,
                                          keyboardType: TextInputType.number,
                                          decoration: InputDecoration(
                                              hintText: '请输入起始序号'))),
                                  _textButton(width: 180, '重命名', onPressed: () {
                                    controller.reName();
                                  }),
                                  Offstage(
                                      offstage: controller.imageList.isEmpty,
                                      child: TextButton(
                                          onPressed: () {
                                            controller.fileLocation();
                                          },
                                          child: Text(
                                            '文件位置',
                                            style: TextStyle(
                                                color: Colors.blueAccent),
                                          )))
                                ],
                              )),
                          SizedBox(
                            height: 15,
                          ),
                          Expanded(
                              child: Container(
                                  width: windowWidth * 0.97,
                                  child: MultiImagePickerView(
                                      controller: controller.pickController,
                                      padding: const EdgeInsets.all(10),
                                      builder: (context, imageFile) {
                                        return GestureDetector(
                                            onTap: () {
                                              // controller.reNameFile(imageFile.path!);
                                            },
                                            child: Column(
                                              children: [
                                                Expanded(
                                                    child: Container(
                                                        width:
                                                            windowWidth * 0.2,
                                                        child:
                                                            DefaultDraggableItemWidget(
                                                          imageFile: imageFile,
                                                          fit: BoxFit.cover,
                                                        ))),
                                                Text(imageFile.path.toString()),
                                              ],
                                            ));
                                      }))),
                        ],
                      ),
                      // _right(controller)
                    ],
                  )));
        });
  }

  _right(RenameController controller) {
    return Expanded(
        child: ListView.builder(
            itemCount: controller.imageList.length,
            padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
            itemBuilder: (context, index) {
              return GestureDetector(
                  onTap: () {},
                  child: Container(
                    height: 30,
                    child: Text(
                      controller.imageList[index].path.toString(),
                      style: TextStyle(color: Colors.blueAccent),
                    ),
                  ));
            }));
  }

  _textButton(String text, {double width = 90, Function? onPressed}) {
    return Container(
        height: width,
        margin: EdgeInsets.only(left: 15, right: 20),
        alignment: Alignment.center,
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white)));
  }
}
